package cn.tx;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

/**
 * @author Administrator
 * @title: ${NAME}
 * @projectName tx-servlet1
 * @description: TODO
 * @date 2019/4/1021:36
 */
public class ConfigServlet extends HttpServlet {

    @Override
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        // 获取该Servlet的初始化参数  根据参数名称获取
        String company = config.getInitParameter("company");
        System.out.println(company);
        System.out.println("-----------------------");

        // 获取所有参数 获取到所有参数名称的枚举集合
        Enumeration<String> names = config.getInitParameterNames();
        // 遍历该枚举 获取参数名称和值
        while (names.hasMoreElements()){
            // 获取一个参数名称
            String name = names.nextElement();
            String value = config.getInitParameter(name);
            System.out.println(name + ":" + value);
        }


    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
